package com.fyt.ZhongYaoApp.mapper;

import com.fyt.ZhongYaoApp.pojo.ShoppingCar;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ShoppingCarMapper {

    // 动态sql
    List<ShoppingCar> list(ShoppingCar shoppingCar);

    // 更新数量
    @Update("update shopping_car set number = #{number} , amount = #{amount} where id = #{id}")
    void updateNumberById(ShoppingCar shoppingCar);

    // 插入购物车数据
    @Insert("insert into shopping_car(name,image,user_id,shop_id,shop_cat,create_time,number,amount)" +
            "values (#{name},#{image},#{userId},#{shopId},#{shopCat},#{createTime},#{number},#{amount})")
    void insert(ShoppingCar shoppingCar);

    @Delete("delete from shopping_car where user_id = #{userId}")
    void deleteById(Integer userId);
}
